package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.ClassInfo;
import cn.wolfcode.crm.mapper.ClassInfoMapper;
import cn.wolfcode.crm.query.ClassInfoQuery;
import cn.wolfcode.crm.service.IClassInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClassInfoServiceImpl implements IClassInfoService {

    @Autowired
    private ClassInfoMapper classInfoMapper;

    @Override
    public void delete(Long id) {
        classInfoMapper.deleteRelation(id);
        classInfoMapper.deleteByPrimaryKey(id);
    }


    @Override
    public void save(ClassInfo classInfo,Long employee_id) {
        classInfoMapper.insertRelation(classInfo.getId(), employee_id);
        classInfoMapper.insert(classInfo);
    }

    @Override
    public ClassInfo get(Long id) {
        return classInfoMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<ClassInfo> listAll() {
        return classInfoMapper.selectAll();
    }

    @Override
    public void update(ClassInfo classInfo, Long employee_id) {
        if(employee_id != null){
            classInfoMapper.deleteRelation(classInfo.getId());
        }
        classInfoMapper.insertRelation(classInfo.getId(), employee_id);
        classInfoMapper.updateByPrimaryKey(classInfo);
    }


    /**
     *
     * @param qo
     * @return
     */
    @Override
    public PageInfo query(ClassInfoQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());

        //查询结果集
        List<ClassInfo> list = classInfoMapper.selectForList(qo);
        return new PageInfo(list);
    }
}
